Skip to content

implement pod exec websockets v5#2486

Merged
k8s-ci-robot merged 4 commits into
kubernetes-client:masterfrom
aojea:exec_v5
May 13, 2026
Merged

implement pod exec websockets v5#2486
k8s-ci-robot merged 4 commits into
kubernetes-client:masterfrom
aojea:exec_v5

Conversation

@aojea
Copy link
Copy Markdown
Contributor

@aojea aojea commented Dec 14, 2025

/kind feature
/kind api-change
/kind deprecation

support new exec v5 websocket subprotocol
- [KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/4006-transition-spdy-to-websockets#proposal-new-remotecommand-sub-protocol-version---v5channelk8sio

cc: @yliaog @siyuanfoundation

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Dec 14, 2025
@k8s-ci-robot k8s-ci-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Dec 14, 2025
@k8s-ci-robot k8s-ci-robot added kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 14, 2025
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @aojea!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 14, 2025
@k8s-triage-robot
Copy link
Copy Markdown

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 14, 2026
@k8s-triage-robot
Copy link
Copy Markdown

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 13, 2026
@seans3
Copy link
Copy Markdown

seans3 commented Apr 23, 2026

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Apr 23, 2026
@seans3
Copy link
Copy Markdown

seans3 commented Apr 23, 2026

/assign

@seans3
Copy link
Copy Markdown

seans3 commented May 6, 2026

/lifecycle frozen

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@seans3: The lifecycle/frozen label cannot be applied to Pull Requests.

Details

In response to this:

/lifecycle frozen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown

@seans3 seans3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and substantially complete.

One high-level observation: I believe falling back to v4.channel.k8s.io is the right approach for backwards compatibility, but we should probably note that for clusters < v1.30, the client will silently revert to the broken behavior and hang on EOF.

I've left a few minor inline comments mostly about tests and constants.

del self._channels[channel]
return ret

if channel in self._closed_channels:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this same short-circuiting code in peek_channel and read_channel ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Comment thread kubernetes/base/stream/ws_client.py Outdated
"""Close a channel (v5 protocol only)."""
if self.subprotocol != V5_CHANNEL_PROTOCOL:
return
data = bytes([255, channel])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we define a constant (e.g. CLOSE_CHANNEL = 255 or V5_HALF_CLOSE = 255) for this magic number, and reference the constant?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to have a constant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack


mock_ws.send.assert_not_called()

def test_update_receives_close_v5(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an additional unit test to verify how readline_channel handles a closed channel with leftover data?

While the current unit tests cover the parsing of the close signal itself, the new logic you added inside readline_channel—which flushes the remaining buffer even if it lacks a newline—is currently untested. Having a test that asserts readline_channel successfully flushes leftover data (e.g. "hello") and then returns an empty string on the subsequent call would ensure this specific edge-case logic is protected from future regressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests also for read_channel and peek_channel to validate channels are drained and follow the expected semantics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Comment thread kubernetes/e2e_test/test_client.py Outdated
Comment thread kubernetes/base/stream/ws_client_test.py Outdated
@seans3
Copy link
Copy Markdown

seans3 commented May 6, 2026

/assign @yliaog

Comment thread kubernetes/base/stream/ws_client.py Outdated
# In Py3, iterating bytes gives int, but indexing bytes gives int.
# websocket-client frame.data might be bytes.

if channel == 255 and self.subprotocol == V5_CHANNEL_PROTOCOL: # v5 CLOSE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to replace 255 with a constant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

implementation is able to signal a channel is closed to the other side.
Clients are also able to drain the closed channels.
@aojea aojea changed the title [WIP] implement pod exec v5 implement pod exec websockets v5 May 12, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 12, 2026
@aojea
Copy link
Copy Markdown
Contributor Author

aojea commented May 12, 2026

@seans3 @yliaog PTAL

@seans3
Copy link
Copy Markdown

seans3 commented May 12, 2026

Looks great--thanks.

/lgtm

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@seans3: changing LGTM is restricted to collaborators

Details

In response to this:

Looks great--thanks.

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

if resp.subprotocol != "v5.channel.k8s.io":
resp.close()
api.delete_namespaced_pod(name=name, body={}, namespace='default')
self.skipTest("Skipping test: v5.channel.k8s.io subprotocol not negotiated")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is skipped in the e2e test flow: https://github.com/kubernetes-client/python/actions/runs/25740181177/job/75636044165

how to make it run?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubernetes/e2e_test/test_client.py::TestClient::test_pod_exec_close_channel SKIPPED

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to get a more recent version of kind, let me update that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was not the version, the e2e tests were not initializing the subprotocol so it never matched ... now the client if is not preconfigured, uses the subprotocol obtained during the negotiation

@aojea
Copy link
Copy Markdown
Contributor Author

aojea commented May 12, 2026

@yliaog is it normal for the e2e tests to take so long? they take more than 3 hours, that sounds like a lot

@aojea
Copy link
Copy Markdown
Contributor Author

aojea commented May 12, 2026

6a83c7e

it runs in less than 2 minutes in my vm 6a83c7e , it seems there can be a deadlock on stop

@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 13, 2026

the e2e takes a long time in the informer tests, i have not had a chance to look into why it takes so long.

@aojea
Copy link
Copy Markdown
Contributor Author

aojea commented May 13, 2026

the e2e takes a long time in the informer tests, i have not had a chance to look into why it takes so long.

Fixed im the latest commit, there was deadlockimg when.closing, added a comment

@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 13, 2026

thanks for the fix @aojea

thanks for the review @seans3

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, yliaog

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 13, 2026
@k8s-ci-robot k8s-ci-robot merged commit 50d9ffb into kubernetes-client:master May 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants